﻿using App.Chat.Contract;

namespace App.Chat.Auth
{
    public static class HttpContextExtension
    {
        public static string? GetLoginToken(this HttpContext context)
        {
            //优先在请求头中获取sessionid，其次是请求参数
            var tokenQuery = context.Request.Headers
                   .Where(x => x.Key.Equals(CommonConst.LoginTokenMark));
            if (tokenQuery.Any())
                return tokenQuery
                .FirstOrDefault().Value.ToString();
            if (context.Request.Query.ContainsKey(CommonConst.LoginTokenMark))
                return context.Request.Query[CommonConst.LoginTokenMark].ToString();
            return null;
        }
    }
}
